package com.google.gson.internal.bind;

import com.google.gson.a.a;
import com.google.gson.b.d;
import com.google.gson.internal.bind.TypeAdapter.Factory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public final class o extends TypeAdapter {
    public static final Factory a = new Factory() {
        public TypeAdapter create(l lVar, a aVar) {
            return aVar.a() == Object.class ? new o(lVar) : null;
        }
    };
    private final l b;

    private o(l lVar) {
        this.b = lVar;
    }

    public void a(d dVar, Object obj) throws IOException {
        if (obj == null) {
            dVar.f();
            return;
        }
        TypeAdapter a = this.b.a(obj.getClass());
        if (a instanceof o) {
            dVar.d();
            dVar.e();
            return;
        }
        a.a(dVar, obj);
    }

    public Object b(com.google.gson.b.a aVar) throws IOException {
        switch (aVar.f()) {
            case BEGIN_ARRAY:
                List arrayList = new ArrayList();
                aVar.a();
                while (aVar.e()) {
                    arrayList.add(b(aVar));
                }
                aVar.b();
                return arrayList;
            case BEGIN_OBJECT:
                Map linkedHashMap = new LinkedHashMap();
                aVar.c();
                while (aVar.e()) {
                    linkedHashMap.put(aVar.g(), b(aVar));
                }
                aVar.d();
                return linkedHashMap;
            case STRING:
                return aVar.h();
            case NUMBER:
                return Double.valueOf(aVar.k());
            case BOOLEAN:
                return Boolean.valueOf(aVar.i());
            case NULL:
                aVar.j();
                return null;
            default:
                throw new IllegalStateException();
        }
    }
}
